package client;

import java.awt.GridLayout;
import java.util.*;
import javax.swing.*;
import common.*;

//This is the final score board available when the round
//enters the results phase.

public class SwingScoreboard extends JFrame {
	private static final long serialVersionUID = 4762985302695108535L;

	public SwingScoreboard (Round r) {
		
		List<Player> p = r.getPlayers();
		Collections.sort(p);
		
		String [] col = {"RANK","PLAYER NAME","SCORE"};
		String [][] data = new String [p.size()][col.length];
		for (int i = 0; i<p.size(); ++i) {
			data[i][0] = (i+1) + "";
			data[i][1] = (i == 0) ? "*" + p.get(i).getName() + "*" : p.get(i).getName();
			data[i][2] = ""+ String.format("%.2f", p.get(i).getScore());
		}
		setTitle("Round " + r.getID() + " Results | Winner : " + data[0][1]);
		
		JPanel total = new JPanel();
		total.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
		total.setLayout(new GridLayout(1,col.length,20,20));
		for (int i = 0; i<col.length; ++i) {			
			String s = "<html>" + col[i] + "<br><br>";
			for (int j = 0; j<data.length; ++j) s+= data[j][i]+"<br>";
			total.add(new JLabel(s+"</html>"));
		}
		this.add(total);
		
		this.pack();
		this.validate();
		this.setDefaultCloseOperation ( JFrame.DISPOSE_ON_CLOSE );
	}
}
